<template>
  <div class="app-container">

<h2>温馨提示：评星从1-5</h2>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="名称" prop="constructionName">
        <el-input
          v-model="queryParams.constructionName"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="类型" prop="constructionType">
        <el-select v-model="queryParams.constructionType" placeholder="请选择类型" clearable size="small">
          <el-option label="建房施工" value="0" />
          <el-option label="装修施工" value="1" />
          <el-option label="同城安装" value="6" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="施工队ID" align="center" prop="constructionId" />
      <el-table-column label="名称" align="center" prop="constructionName" :show-overflow-tooltip="true" />
      <el-table-column label="评分" align="center" prop="threeTeamId" />
      <el-table-column label="施工队销售价格" align="center" prop="price" />
      <el-table-column label="施工队录入时间" align="center" prop="constructionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.constructionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="施工队描述" align="center" prop="descript" :show-overflow-tooltip="true" />
      <el-table-column label="分类" align="center" prop="constructionType" >
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.constructionType == 0">建房施工</el-tag>
          <el-tag type="success" v-else-if="scope.row.constructionType == 1">装修施工</el-tag>
          <el-tag type="" v-else-if="scope.row.constructionType == 6">同城安装</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="最后修改时间" align="center" prop="modifiedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifiedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="队伍人数" align="center" prop="teamNumber" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应商信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="评分" prop="threeTeamId">
<!--          <el-input v-model="form.threeTeamId" placeholder="评分" />-->

          <span class="demonstration">区分颜色</span>
          <el-rate
            v-model="form.threeTeamId"
            :colors="colors">
          </el-rate>

        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { pingfenlistInfo,getInfo,updateInfo } from "@/api/pingfen";

  export default {
        name: "index",
      data() {
        return {
          colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
          // 遮罩层
          loading: true,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 供应商信息表格数据
          infoList: [],
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            constructionCore: null,
            constructionName: null,
            oneTeamId: null,
            twoTeamId: null,
            threeTeamId: null,
            supplierId: null,
            teamId: null,
            price: null,
            publishStatus: null,
            auditStatus: null,
            constructionDate: null,
            descript: null,
            modifiedTime: null,
            teamNumber: null,
            constructionType: null
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
            constructionCore: [
              { required: true, message: "施工队编码不能为空", trigger: "blur" }
            ],
            constructionName: [
              { required: true, message: "姓名不能为空", trigger: "blur" }
            ],
            supplierId: [
              { required: true, message: "商品/施工队的供应商ID不能为空", trigger: "blur" }
            ],
            teamId: [
              { required: true, message: "施工队的分类ID不能为空", trigger: "blur" }
            ],
            price: [
              { required: true, message: "施工队销售价格不能为空", trigger: "blur" }
            ],
            publishStatus: [
              { required: true, message: "上下架状态：0上架1下架不能为空", trigger: "blur" }
            ],
            auditStatus: [
              { required: true, message: "审核状态：0未审核，1已审核不能为空", trigger: "blur" }
            ],
            constructionDate: [
              { required: true, message: "施工队录入时间不能为空", trigger: "blur" }
            ],
            descript: [
              { required: true, message: "施工队描述不能为空", trigger: "blur" }
            ],
            modifiedTime: [
              { required: true, message: "最后修改时间不能为空", trigger: "blur" }
            ],
            delFlag: [
              { required: true, message: "删除的标识不能为空", trigger: "blur" }
            ],
          }
        };
      },
      created() {
        this.getList();
      },
      methods: {
        /** 查询供应商信息列表 */
        getList() {
          this.loading = true;
          pingfenlistInfo(this.queryParams).then(response => {
            this.infoList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        },
        // 取消按钮
        cancel() {
          this.open = false;
          this.reset();
        },
        // 表单重置
        reset() {
          this.form = {
            constructionId: null,
            constructionCore: null,
            constructionName: null,
            oneTeamId: null,
            twoTeamId: null,
            threeTeamId: null,
            supplierId: null,
            teamId: null,
            price: null,
            publishStatus: 0,
            auditStatus: 0,
            constructionDate: null,
            descript: null,
            modifiedTime: null,
            delFlag: null,
            teamNumber: null,
            constructionType: null
          };
          this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
          this.ids = selection.map(item => item.constructionId)
          this.single = selection.length!==1
          this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
          this.reset();
          this.open = true;
          this.title = "添加供应商信息";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
          this.reset();
          const constructionId = row.constructionId || this.ids
          getInfo(constructionId).then(response => {
            this.form = response.data;
            this.open = true;
            this.title = "评星";
          });
        },
        /** 提交按钮 */
        submitForm() {
          this.$refs["form"].validate(valid => {
            if (valid) {
              if (this.form.constructionId != null) {
                updateInfo(this.form).then(response => {
                  if (response.code === 200) {
                    this.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                  }
                });
              } else {
                addInfo(this.form).then(response => {
                  if (response.code === 200) {
                    this.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                  }
                });
              }
            }
          });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
          const constructionIds = row.constructionId || this.ids;
          this.$confirm('是否确认删除供应商信息编号为"' + constructionIds + '"的数据项?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            return delInfo(constructionIds);
          }).then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          }).catch(function() {});
        },
        /** 导出按钮操作 */
        handleExport() {
          const queryParams = this.queryParams;
          this.$confirm('是否确认导出所有供应商信息数据项?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            return exportInfo(queryParams);
          }).then(response => {
            this.download(response.msg);
          }).catch(function() {});
        }
      }
    }
</script>

<style scoped>

</style>
